

mainloadui=CS.UnityEngine.GameObject;
 rapidjson = require('rapidjson')

function LuaMain()

print(" LuaMain ")
local rul=self:Lua_SetUpdateURL("http://arstatic.xiaomayunkeji.com");
print(rul);
									
local rul2=self:Lua_SetUpdateURL2("http://arapi.xiaomayunkeji.com");
print(rul2);

	local ab=self.assetBudleManager:GetAssetBundle("loading","loading/loading");
	mainloadui = CS.UnityEngine.Object.Instantiate(ab:LoadAsset("loading").gameObject).gameObject;
	mainloadui.transform:SetParent(self.transform);
	MainLoadManager=mainloadui:AddComponent(typeof(CS.MainLoadManager));
	self.objectManager:AddModularGameObject("loading",mainloadui);
	LoadUI=self.objectManager:fandGameobject("loading").transform:Find("Load").gameObject;
	Text=LoadUI.transform:Find("Text").gameObject;
	Text:GetComponent("Text").text="检查更新中。。。";
	
	local mainloaduiTransform=mainloadui:GetComponent("RectTransform");
	mainloaduiTransform.localScale=CS.UnityEngine.Vector3.one;
	mainloaduiTransform.sizeDelta=CS.UnityEngine.Vector2(0,0);
	mainloaduiTransform.localPosition=CS.UnityEngine.Vector3.zero;
	mainloaduiTransform:SetSiblingIndex(999);
	
	ab=self.assetBudleManager:GetAssetBundle("loading","loading/prompt");
	PromptUI = CS.UnityEngine.Object.Instantiate(ab:LoadAsset("prompt").gameObject).gameObject;
	PromptUI.transform:SetParent(self.transform);
	self.objectManager:AddModularGameObject("prompt",PromptUI);
	local RectTransform=PromptUI:GetComponent("RectTransform");
	RectTransform.localRotation=CS.UnityEngine.Quaternion.Euler(0,0,0);
	RectTransform.localScale=CS.UnityEngine.Vector3.one;
	--RectTransform.sizeDelta=CS.UnityEngine.Vector2.zero;
	RectTransform.localPosition=CS.UnityEngine.Vector3.zero;
	RectTransform:SetSiblingIndex(1000);
	PromptUI:SetActive(false);
	mainloadui:SetActive(false);
	if(CS.UnityEngine.Application.platform == CS.UnityEngine.RuntimePlatform.IPhonePlayer)then
 		self:GetISupdate("http://arstatic.xiaomayunkeji.com/StreamingAssets/isupdate.txt",ISupdate);
	 else
		ISupdate('1')
	end
end
function ISupdate(jd)  
	isupdata=jd;
	if(isupdata=='0') then
		mainloadui:SetActive(false);
		back();
	else
		mainloadui:SetActive(true);
		json={}
		json[1]=rapidjson.decode('{"Loacl": {"Url": "/ui/Updateconfig.Update","Ctype": 1,"Rtype": 1},"Server": {"Url": "/ui/Updateconfig.Update","Ctype": 1,"Rtype": 1}}')
		json[2]=rapidjson.decode('{"Loacl": {"Url": "/ui/LuaUpdateconfig.Update","Ctype": 1,"Rtype": 2},"Server": {"Url": "/ui/LuaUpdateconfig.Update","Ctype": 1,"Rtype": 2}}')
		json[3]=rapidjson.decode('{"Loacl": {"Url": "ar/getUpdatePicture.Update","Ctype": 1,"Rtype": 3},"Server": {"Url": "/ar/getUpdatePicture","Ctype": 2,"Rtype": 3}}')
		json[4]=rapidjson.decode('{"Loacl": {"Url": "/model/Updateconfig.Update","Ctype": 1,"Rtype": 1},"Server": {"Url": "/model/Updateconfig.Update","Ctype": 1,"Rtype": 1}}')
		
		local w1 = rapidjson.encode(json)
		self.loadManager1:loadConfig(w1,function(jd)
			local t = rapidjson.decode(jd)
			if(t.Error=='null') then
				if(t.count==0) then
					
					back();
					--SetMainLoadManager(t.count,0,"不用geng x");
				else
					UpdateCunt=t.count;
					SetMainLoadManager(t.count,0,"等待更新");
					self.loadManager1:StartUpdate(UpdateCallBack);
				end
			else 
				SetPromptUI(isUpdate_PromptBack,"确 定",false,"访问服务器错误！请重启"..t.Error)
			end
		end);
	end
end

UpdateCunt2=0;
function UpdateCallBack(jd)
	local t1 = rapidjson.decode(jd);
	if(t1.Error=='null') then
		UpdateCunt2 = UpdateCunt2 + 1 ;
		SetMainLoadManager(UpdateCunt,UpdateCunt2,"更新中...");
		return;
	elseif(t1.Error=='wan') then
		back();
		return;
	else
		SetPromptUI(isUpdate_PromptBack,"确 定",false,"访问服务器错误！请重启"..t1.Error)
	end
end

function SetMainLoadManager(i,k,p)
	MainLoadManager:SetMainLoadProgress(i,k,p);
end
function Lua_pass(pass)
	MainLoadManager:SetMainLoadProgress2(pass);
end 

function SetPromptUI(Event,t,isFo,Msg)
	PromptUI:SetActive(true)
	local Button02=self.objectManager:fandGameobject("prompt","Button02")
	Button02:SetActive(isFo)
	Button02:GetComponent("Button").onClick:AddListener(
		function()
			PromptUI:SetActive(false)
		end)
	local Button01=self.objectManager:fandGameobject("prompt","Button01")
	Button01:GetComponent("Button").onClick:AddListener(function()
			Event(PromptUI)
		end)
	Button01Text=self.objectManager:fandGameobject("prompt","Button01","Text")
	Button01Text:GetComponent("Text").text=t
	local MsgText=self.objectManager:fandGameobject("prompt","Text")
	MsgText:GetComponent("Text").text=Msg

end
function isUpdate_PromptBack(PromptUI)
	PromptUI:SetActive(false)
end
function back()


 AppLuaBehaviour=self:GetComponent("AppLuaBehaviour")
 AppLuaBehaviour:SetLuaScripts("ui/UIMananger.lua");
end


